#pragma once

#include <boost/asio.hpp>

class IOServicePool {
public:
    static IOServicePool &GetInstance();

    IOServicePool(const IOServicePool &) = delete;

    ~IOServicePool();

    IOServicePool &operator=(const IOServicePool &) = delete;

    boost::asio::io_context &GetIOContext();

    void stop();

private:
    explicit IOServicePool(unsigned int thread_nums = std::thread::hardware_concurrency());

    std::vector<boost::asio::io_context> _io_contexts;
    std::vector<std::unique_ptr<boost::asio::io_context::work> > _io_works;
    std::vector<std::thread> _threads;
    int _next_io_context;
};
